/*
    XTU OJ: 1194
    by: fifth_light
*/

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

#define TRIANGLE_LENGTH 1010

#define mod 1000000007
int triangle[TRIANGLE_LENGTH][TRIANGLE_LENGTH];

void prepare_triangle() {
    for(int y = 0; y < TRIANGLE_LENGTH; y++) {
        for(int x = 0; x <= y; x++) {
            if (y == 0 || y == TRIANGLE_LENGTH - 1) {
                triangle[y][x] = 1;
            } else {
                triangle[y][x] = (triangle[y - 1][x - 1] + triangle[y - 1][x]) % mod;
            }
        }
    }
}

int64_t d_table[TRIANGLE_LENGTH];

void prepare_d() {
    d_table[0] = 0;
    d_table[1] = 0;
    d_table[2] = 1;
    for (int i = 3; i < TRIANGLE_LENGTH; i++) {
        d_table[i] = (((i - 1) % mod) * ((d_table[i - 2] + d_table[i - 1]) % mod)) % mod;
    }
}

int C(int n, int m) {
    return triangle[n][m];
}

int main(void) {
    prepare_triangle();
    prepare_d();
    // puts("Prepare!");
    int n, k;
    while (scanf("%d%d", &n, &k) == 2) {
        if (n == 0 && k == 0) {
            break;
        }
        // printf("C: %d, D: %" PRId64 "\n", C(n, k), d_table[k]);
        if (k == 0) {
            // 刚好0个送错，即全部送对
            puts("1");
        } else {
            printf("%" PRId64 "\n", (C(n, k) * d_table[k]) % mod);
        }
    }
    return 0;
}
